package com.abysscore.yachtdesign;

import java.awt.Color;
import java.util.Vector;
/*
 *      {---------------------------------------------------------------------------------------------------}
     {                                           TFreeSubdivisionSurface                                 }
     {                                                                                                   }
     { This is the subdivision surface used for modelling the hull.                                      }
     { This is actually a quad-triangle subdivision surface as publisehed in the articles:               }
     {                                                                                                   }
     {   "Quad/triangle subdivision" by J. Stam & C. Loop http://research.microsoft.com/~cloop/qtEG.pdf  }
     {   "On C2 triangle/quad subdivision" by Scott Schaeffer & Joe Warren                               }
     {                                                                                                   }
     {---------------------------------------------------------------------------------------------------}
 */
public class TFreeSubdivisionSurface extends TFreeEntity {
	private TFasterList FControlPoints            ;          // List with controlpoints, which can be changed by the user
	private TFasterList FControlEdges             ;          // List with controledges, which can be changed by the user
	private TFasterList FControlFaces              ;          // List with controlfaces, which can be changed by the user
	private TFasterList FControlCurves             ;          // list with mastercurves
	private TFasterList FPoints                    ;          // List with points obtained by subdividing the surface
	private TFasterList FEdges                     ;          // this list edges obtained by subdividing the controledges
	private TFasterList FLayers                    ;          // All layers are stored in this list
	private TFasterList FSelectedControlPoints;          // Controlpoints which are selected by the user are put in this list
	private TFasterList FSelectedControlEdges;          // List with currently selected controledges
	private TFasterList FSelectedControlCurves;          // List with currently selected controlcurves
	private TFasterList FSelectedControlFaces;          // List with currently selected controlfaces
	private TFREESubdivisionLayer FActiveLayer               ;// Currently active layer, may not be nil!
	private boolean FShowControlNet            ;              // Flag to switch controlpoints and control-edges visibility
	private boolean FInitialized;              // Flag to check if the surface has been initialised.
	private boolean FShowInteriorEdges;              // Switch to turn on drawing off all interior edges as well.
	private boolean FDrawMirror;              // If this is set tot true, the other imaginary half (starboard side) will be drawn aswell
	private TFreeSubdivisionMode FSubdivisionMode         ; // Varaiable to switch between quad-triangle and Catmull Clark subdivision
	private int FDesiredSubdivisionLevel  ;	
	private byte FCurrentSubdivisionLevel;
	private Color FCreaseColor              ;               // color of descendants from creaseedges
	private Color FCreaseEdgeColor;               // Color of crease controledges
	private int FLastusedLayerID         ;
	private TNotifyEvent FOnChangeLayerData        ;         // Event which is raised when layer-data has been changed
	private TChangeActiveLayerEvent FOnChangeActiveLayer      ; // Event raised when the active layer is changed
	private TNotifyEvent FOnSelectItem              ;         // This event is raised whenever an item (such as controlpoint, controledge or controlface) is selected or deselected
	
	private Color FUnderWaterColor          ;               // Color used for shading the underwater part
	private T3DPlane FWaterlinePlane           ;             // This plane is used to clip the hull, and shade the underwatership in a different color
	private boolean FShadeUnderWater;              // Switch to turn under water shading on or off
	private boolean FShowNormals ;              // show normals of selected controlfaces
	private int FControlPointSize;
	private Color FEdgeColor;               // Color of normal edges (no crease)
	private Color FSelectedcolor;               // Default color for selected items
	private Color FCreasePointColor;               // Color for vertices connected to two creaseedges
	private Color FRegularPointColor;               // Color of regular controlpoints
	private Color FCornerPointColor;               // color of cornerpoints
	private Color FDartPointColor;
	private Color FLayerColor;               // Default color for layers;
	private Color FNormalColor;               // color of surface normals
	private Color FLeakColor;               // color of leak points
	private Color FCurvatureColor;               // color of the curvature plot of controlcurves
	private Color FControlCurveColor;
	private Color FZebraColor;
	private boolean FShowCurvature;
	private boolean FShowControlCurves;
	private double FCurvatureScale;
	private double[] FGausCurvature;          // list with precalculated values of gauss. curvature in each point, used for shading
	private double FMinGaussCurvature;
	private double FMaxGaussCurvature;
	private double FMainframeLocation;


	private TFreeSubdivisionControlPoint FGetControlPoint(int Index) {
		return null;
	}
	private TFreeSubdivisionControlCurve FGetControlCurve(int Index) {
		return null;
	}
	private TFreeSubdivisionControlEdge FGetControlEdge(int Index) {
		return null;
	}
	private TFreeSubdivisionControlFace FGetControlFace(int Index) {
		return null;
	}
	private boolean FGetGaussCurvatureCalculated() {
		return false;
	}
	private TFREESubdivisionLayer FGetLayer(int Index) {
		return null;
	}
	private int FGetNumberOfControlPoints() {
		return 0;
	}
	private int FGetNumberOfControlEdges() {
		return 0;
	}
	private int FGetNumberOfControlCurves() {
		return 0;
	}
	private int FGetNumberOfControlFaces() {
		return 0;
	}
	private int FGetNumberOfFaces() {
		return 0;
	}
	private int FGetNumberOfLayers() {
		return FLayers.Count();
	}
	private int FGetNumberOfLockedPoints() {
		return 0;
	}
	private TFreeSubdivisionPoint FGetPoint(int Index) {
		return null;
	}
	private TFreeSubdivisionEdge FGetEdge(int Index) {
		return null;
	}
	private int FGetNumberOfPoints() {
		return 0;
	}
	private int FGetNumberOfSelectedControlCurves() {
		return 0;
	}
	private int FGetNumberOfSelectedControlEdges() {
		return 0;
	}
	private int FGetNumberOfSelectedControlFaces() {
		return 0;
	}
	private int FGetNumberOfSelectedControlPoints() {
		return 0;
	}
	private int FGetNumberOfSelectedLockedPoints() {
		return 0;
	}
	private int FGetNumberOfEdges() {
		return 0;
	}
	private TFreeSubdivisionControlCurve FGetSelectedControlCurve(int Index) {
		return null;
	}
	private TFreeSubdivisionControlEdge FGetSelectedControlEdge(int Index) {
		return null;
	}
	private TFreeSubdivisionControlFace FGetSelectedControlFace(int Index) {
		return null;
	}
	private TFreeSubdivisionControlPoint FGetSelectedControlPoint(int Index) {
		return null;
	}
	private int FRequestNewLayerID() {
		return 0;
	}
	private void FSetActiveLayer(TFREESubdivisionLayer Val) {
	}
	private void FSetBuild(boolean Val) {
	}                
	private void FSetDesiredSubdivisionLevel(int val) {
		FDesiredSubdivisionLevel =val;
	}
	private void FSetFShowControlNet(boolean Val) {
	}
	private void FSetSubdivisionMode(TFreeSubdivisionMode val) {
	}


	public void AddControlCurve(TFreeSubdivisionControlCurve Curve) {
	}
	public TFreeSubdivisionControlEdge AddControlEdge(TFreeSubdivisionPoint P1, TFreeSubdivisionPoint P2) {
		return null;
	}
	public TFreeSubdivisionControlFace AddControlFace(Vector<T3DCoordinate> Points, int NoPoints) {
		return null;
	}
	public TFreeSubdivisionControlFace AddControlFace(TFasterList Points, boolean CheckEdges) {
		return null;
	}
	public TFreeSubdivisionControlFace AddControlFace(Vector Points, boolean CheckEdges) {
		return null;
	}
	public TFreeSubdivisionControlFace AddControlFace(TFasterList Points,boolean CheckEdges, TFREESubdivisionLayer Layer) {
		return null;
	}
	public TFreeSubdivisionControlPoint AddControlPoint(T3DCoordinate P) {
		return null;
	} 
	public void AddControlPoint(TFreeSubdivisionControlPoint P) {
	} 
	public TFreeSubdivisionControlPoint AddControlPoint() {
		return null;
	} // Adds a new controlpoint at 0,0,0 without checking other points
	public TFREESubdivisionLayer AddNewLayer() {
		TFREESubdivisionLayer Result = new TFREESubdivisionLayer(this);
		FLayers.Add(Result);
		Result.LayerID(FRequestNewLayerID());
		ActiveLayer(Result);
		if (FOnChangeLayerData != null)
			FOnChangeLayerData = new TNotifyEvent(this);
		return Result;
	}
	public void AssembleFacesToPatches(TFasterList Layers, TFreeAssembleMode Mode, Vector<TFreeFaceGrid> AssembledPatches, int NAssembled) {
	}
	public void CalculateGaussCurvature() {
	}                                       // Calculate Gauss. curvature in each point of the mesh and store it in a array
	public void Clear() {
	}       
	public void ClearFaces() {
	}
	public void Clearselection() {
	}
	public void ConvertToGrid(TFreeFaceGrid Input, int Cols, int Rows, Vector<TFreeSubdivisionPoint> Grid) {
	}
	public void Edge_Connect() {
	}
	public void ExportFeFFile(TStringList Strings) {
	}
	public void ExportObjFile(boolean ExportControlNet, TStringList Strings) {
	}
	public void Extents(T3DCoordinate Min, T3DCoordinate Max) {
	}
	public void ExtrudeEdges(TFasterList Edges, T3DCoordinate Direction) {
	}
	public void CalculateIntersections(T3DPlane Plane, TFasterList Faces, TFasterList Destination) {
	}
	public TFreeSubdivisionSurface() {
	}  
	public void Draw(TFreeViewport Viewport) {
	} 
	public TFreeSubdivisionEdge EdgeExists(TFreeSubdivisionPoint P1, TFreeSubdivisionPoint P2) {
		int I=-1;
		TFreeSubdivisionEdge Edge;

		TFreeSubdivisionEdge Result=null;
		// If the edge exists then it must exist
		// in both the points, therefore only the point
		// with the smallest number of edges has to be checked
		if (P1.FEdges.Count()<=P2.FEdges.Count())
		{
			for (I=1; I<=P1.FEdges.Count();I++)
			{
				Edge=P1.Edge(I-1);
				if (((Edge.FStartpoint==P1) && (Edge.FEndpoint==P2)) || ((Edge.FStartpoint==P2) && (Edge.FEndpoint==P1)))
				{
					Result=Edge;
					break;
				}
			}
		}
		else
			for (I=1; I <=P2.FEdges.Count(); I++)
			{
				Edge=P2.Edge(I-1);
				if (((Edge.FStartpoint==P1) && (Edge.FEndpoint==P2)) || ((Edge.FStartpoint==P2) && (Edge.FEndpoint==P1)))
				{
					Result=Edge;
					break;
				}
			}
		return Result;
	}
	public void ExtractAllEdgeLoops(TFasterList Destination) {
	}
	public void ExtractPointsFromFaces(TFasterList SelectedFaces, TFasterList Points, int LockedPoints) {
	}   // extracts all points that are used by the faces in the selectedfaces list
	public void ExtractPointsFromSelection(TFasterList SelectedPoints, int LockedPoints) {
	}
	public void ImportFEFFile(TStringList Strings, int LineNr) {
	}
	public void ImportGrid(Vector<T3DCoordinate> Points, int Cols, int Rows, TFREESubdivisionLayer Layer) {
	}
	public void Initialize(int PointStartIndex, int EdgeStartIndex, int FaceStartIndex) {
	}
	public boolean IntersectPlane(T3DPlane Plane, boolean HydrostaticsLayersOnly, TFasterList List) {
		return false;
	}
	public void InsertPlane(T3DPlane Plane, boolean AddCurves) {
	}  // inserts points on edges (visible edges only) that intersect the input plane
	public void IsolateEdges(TFasterList Source, TFasterList Destination) {
	}
	public void LoadBinary(TFreeFileBuffer Source) 
	{
		int I=0;
		int N=0;
		TFreeSubdivisionControlPoint Point;
		TFreeSubdivisionControlEdge Edge;
		TFreeSubdivisionControlFace Face;
		TFreeSubdivisionControlCurve Curve;
		TFREESubdivisionLayer Layer;
	
		// First load layerdata
		Source.Load(N);
		if (N!=0)
		{
			// Delete current layers and load new ones
			for (I=1; I<=NumberOfLayers();I++)
				this.Layer(I-1).Delete();
			FLayers.Clear();
			FLayers.Capacity(N);
			for(I=1; I <= N; I++)
			{
	         Layer=AddNewLayer();
	         Layer.LoadBinary(Source);
			}
		}
		else
			;
		if(FOnChangeLayerData!=null)
			FOnChangeLayerData = new TNotifyEvent(this);

		// Read index of active layer
		Source.Load(N);
		ActiveLayer(this.Layer(N));
		if(FOnChangeActiveLayer!=null)
			FOnChangeActiveLayer = new TChangeActiveLayerEvent(this.Layer(0));
		// Read controlpoints
		Source.Load(N);
		FControlPoints.Capacity(N);
		for (I=1; I<=N; I++)
		{
			Point=new TFreeSubdivisionControlPoint(this);
			FControlPoints.Add(Point);
			Point.LoadBinary(Source);
		}
		// Read controlEdges
		Source.Load(N);
		FControlEdges.Capacity(N);
		for(I=1; I<=N; I++)
		{
			Edge=new TFreeSubdivisionControlEdge(this);
			Edge.ControlEdge(true);
			FControlEdges.Add(Edge);
			Edge.LoadBinary(Source);
		}
		if (Source.Version().compareTo(TFreeFileVersion.fv195)>=0)
		{
			// Load controlcurves
			Source.Load(N);
			FControlCurves.Capacity(N);
			for (I=1; I<=N; I++)
			{
				Curve=new TFreeSubdivisionControlCurve(this);
				FControlCurves.Add(Curve);
				Curve.LoadBinary(Source);
			}
		}

	   // Read controlFaces
	   Source.Load(N);
	   FControlFaces.Capacity(N);
	   for (I=1; I<=N; I++)
	   {
		   Face=new TFreeSubdivisionControlFace(this);
		   FControlFaces.Add(Face);
		   Face.LoadBinary(Source);
	   }
	   Build(false);
	   FInitialized=true;
	   if (FOnChangeLayerData!=null)
		   FOnChangeLayerData = new TNotifyEvent(this);
	   if (FOnChangeActiveLayer!=null)
		   FOnChangeActiveLayer= new TChangeActiveLayerEvent(this.Layer(0));
	}
	public void LoadFromStream(int LineNr,TStringList Strings) {
	}
	public void LoadVRMLFile(String Filename) {
	}
	public boolean PointExists(TFreeSubdivisionControlPoint P) {
		return false;
	}
	public void Rebuild() {
	}     
	public void SaveBinary(TFreeFileBuffer Destination) {
	}
	public void SaveToStream(TStringList Strings) {
	}
	public void Selection_Delete() {
	}
	public void SortEdges(TFasterList Edges) {
	}   
	public void SortEdges(TFasterList Edges,TFasterList Points) {
	}
	public void SubDivide() {
	}
               
               
	public TFREESubdivisionLayer ActiveLayer()  { return FActiveLayer; }
	public void ActiveLayer(TFREESubdivisionLayer val)  { FSetActiveLayer(val); }
	public TFreeSubdivisionControlPoint    ControlPoint(int index)   { return FGetControlPoint(index); }
	public int    ControlPointSize()  { return FControlPointSize; }
	public void    ControlPointSize(int val)  { FControlPointSize=val; }
	public TFreeSubdivisionControlCurve    ControlCurve(int index)  { return FGetControlCurve(index); }
	public Color    ControlCurveColor()  { return FControlCurveColor; }
	public void    ControlCurveColor(Color val)  { FControlCurveColor=val; }
	public TFreeSubdivisionControlEdge    ControlEdge(int index)  { return FGetControlEdge(index); }
	public TFasterList    ControlEdges()  { return FControlEdges; }
	public TFreeSubdivisionControlFace    ControlFace(int index)  { return FGetControlFace(index); }
	public byte    CurrentSubdivisionLevel()  { return FCurrentSubdivisionLevel; }
	public Color    CurvatureColor()  { return FCurvatureColor; }
	public void    CurvatureColor(Color val)  { FCurvatureColor=val; }
	public double    CurvatureScale()  { return FCurvatureScale; }
	public void    CurvatureScale(double val)  { FCurvatureScale=val; }
	public Color    CreaseColor()  { return FCreaseColor; }
	public void    CreaseColor(Color val)  { FCreaseColor=val; }
	public Color    CreaseEdgeColor()  { return FCreaseEdgeColor; }
	public void    CreaseEdgeColor(Color val)  { FCreaseEdgeColor=val; }
	public Color    CornerPointColor()  { return FCornerPointColor; }
	public void    CornerPointColor(Color val)  { FCornerPointColor =val; }
	public Color    DartPointColor()  { return FDartPointColor; }
	public void    DartPointColor(Color val)  { FDartPointColor=val; }
	public int    DesiredSubdivisionLevel()  { return FDesiredSubdivisionLevel; }
	public void    DesiredSubdivisionLevel(int i)  {  FSetDesiredSubdivisionLevel(i); }
	public boolean    DrawMirror()  { return FDrawMirror; }
	public void    DrawMirror(boolean val)  { FDrawMirror=val; }
	public boolean    GaussCurvatureCalculated()  { return FGetGaussCurvatureCalculated(); }
	public Color    CreasePointColor()  { return FCreasePointColor; }
	public void    CreasePointColor(Color val)  {  FCreasePointColor=val; }
	public Color    RegularPointColor()  { return FRegularPointColor; }
	public void    RegularPointColor(Color val)  { FRegularPointColor=val; }
	public TFREESubdivisionLayer    Layer(int index)  { return FGetLayer(index); }
	public Color    LayerColor()  { return FLayerColor; }
	public void    LayerColor(Color val)  { FLayerColor=val; }
	public Color    LeakColor()  { return FLeakColor; }
	public void    LeakColor(Color val)  { FLeakColor=val; }
	public double    MainframeLocation()  { return FMainframeLocation; }
	public void    MainframeLocation(double val)  { FMainframeLocation=val; }
	public double    MaxGaussCurvature()  { return FMaxGaussCurvature; }
	public double    MinGaussCurvature()  { return FMinGaussCurvature; }
	public int    NumberOfControlFaces()  { return FGetNumberOfControlFaces(); }
	public int    NumberOfControlEdges()  { return FGetNumberOfControlEdges(); }
	public int    NumberOfControlCurves()  { return FGetNumberOfControlCurves(); }
	public int    NumberOfControlPoints()  { return FGetNumberOfControlPoints(); }
	public int    NumberOfFaces()  { return FGetNumberOfFaces(); }
	public int    NumberOfLayers()  { return FGetNumberOfLayers(); }
	public int    NumberOfLockedPoints()  { return FGetNumberOfLockedPoints(); }
	public int    NumberOfSelectedControlCurves()  { return FGetNumberOfSelectedControlCurves(); }
	public int    NumberOfSelectedControlEdges()  { return FGetNumberOfSelectedControlEdges(); }
	public int    NumberOfSelectedControlFaces()  { return FGetNumberOfSelectedControlFaces(); }
	public int    NumberOfSelectedControlPoints()  { return FGetNumberOfSelectedControlPoints(); }
	public int    NumberOfSelectedLockedPoints()  { return FGetNumberOfSelectedLockedPoints(); }
	public TChangeActiveLayerEvent    OnChangeActiveLayer()  { return FOnChangeActiveLayer; }
	public void    OnChangeActiveLayer(TChangeActiveLayerEvent val)  { FOnChangeActiveLayer=val; }
	public TNotifyEvent    OnChangeLayerData()  { return FOnChangeLayerData; }
	public void    OnChangeLayerData(TNotifyEvent val)  { FOnChangeLayerData=val; }
	public TNotifyEvent    OnSelectItem()  { return FOnSelectItem; }
	public void    OnSelectItem(TNotifyEvent val)  { FOnSelectItem=val; }
	public TFreeSubdivisionPoint    Point(int index)  { return FGetPoint(index); }
	public TFreeSubdivisionEdge    Edge(int index)  { return FGetEdge(index); }
	public Color    EdgeColor()  { return FEdgeColor; }
	public void    EdgeColor(Color val)  { FEdgeColor=val; }
	public Color    NormalColor()  { return FNormalColor; }
	public void    NormalColor(Color val)  { FNormalColor=val; }
	public int    NumberOfEdges()  { return FGetNumberOfEdges(); }
	public int    NumberOfPoints()  { return FGetNumberOfPoints(); }
	public boolean    ShadeUnderWater()  { return FShadeUnderWater; }
	public void    ShadeUnderWater(boolean val)  { FShadeUnderWater=val; }
	public Color    Selectedcolor()  { return FSelectedcolor; }
	public void    Selectedcolor(Color val)  { FSelectedcolor=val; }
	public TFreeSubdivisionControlCurve    SelectedControlCurve(int index)  { return FGetSelectedControlCurve(index); }
	public TFreeSubdivisionControlEdge    SelectedControlEdge(int index)  { return FGetSelectedControlEdge(index); }
	public TFreeSubdivisionControlFace    SelectedControlFace(int index)  { return FGetSelectedControlFace(index); }
	public TFreeSubdivisionControlPoint    SelectedControlPoint(int index)  { return FGetSelectedControlPoint(index); }
	public boolean    ShowControlCurves()  { return FShowControlCurves; }
	public void    ShowControlCurves(boolean val)  {  FShowControlCurves=val; }
	public boolean    ShowControlNet()  { return FShowControlNet; }
	public void    ShowControlNet(boolean val)  { FSetFShowControlNet(val); }
	public boolean    ShowCurvature()  { return FShowCurvature; }
	public void    ShowCurvature(boolean val)  { FShowCurvature=val; }
	public boolean    ShowInteriorEdges()  { return FShowInteriorEdges; }
	public void    ShowInteriorEdges(boolean val)  {  FShowInteriorEdges=val; }
	public boolean    ShowNormals()  { return FShowNormals; }
	public void    ShowNormals(boolean val)  { FShowNormals=val; }
	public TFreeSubdivisionMode    SubdivisionMode()  { return FSubdivisionMode; }
	public void    SubdivisionMode(TFreeSubdivisionMode val)  { FSetSubdivisionMode(val); }
	public Color    UnderWaterColor()  { return FUnderWaterColor; }
	public void    UnderWaterColor(Color val)  { FUnderWaterColor=val; }
	public T3DPlane    WaterlinePlane()  { return FWaterlinePlane; }
	public void    WaterlinePlane(T3DPlane val) { FWaterlinePlane=val; }
	public Color    ZebraColor()  { return FZebraColor; }
	public void    ZebraColor(Color val)  { FZebraColor=val; }
	public int LastusedLayerID()  { return FLastusedLayerID; }
	public void LastusedLayerID(int id)  { FLastusedLayerID=id; }
	
	public Object ControlPoints(int index)  { return FControlPoints.Items(index); }
	public void ControlPoints(TFasterList val)  { FControlPoints=val; }
}
